<?php

class Application_Model_RacksActivos extends Sgit_Model
{  
    protected $_name = 'racks_activos';
    protected $_primary = 'id';


    public function getActivo($id)
    {
        return $this->getActivos(array(), $id);
    }


    public function getActivos($values = array(), $id = null)
    {

        $this->alter();

        $select = $this->getAdapter()->select();
     
        $select->from(array($this->_name));
        $select->joinLeft('racks', 'racks.id = racks_activos.id_rack', array('id_zona','rack'=>'matricula'));
       
      
      
      
        if (!is_null($id))
        {
            $select->where("racks_activos.id= ?", $id);

        } else
        {
            if ($values['id_rack'])
                $select->where('racks_activos.id_rack= ?', $values['id_rack']);
            if ($values['id_zona'])
                $select->where('racks.id_zona= ?', $values['id_zona']);    
        }

        $rows = $this->getAdapter()->fetchAll($select);
        $tipo_activo = new Sgit_Form_Element_Select_TipoActivo('tipo_activo');
        foreach($rows as &$v){
            $v['activo']=$tipo_activo->getMultiOption($v['tipo_activo']);
        }



        if (is_null($id))
            return $rows;
        else
            return $rows[0];


    }
    
} 




